import {emailList} from "../parseEmail/parse_fun";
import md5 from "../../../../assets/js/md5";
import tiyData from "./contact_user_data";



//添加黑名单
export const sendAddEmail = function (self, tiyData) {
  tiyData.tStatus.sendEmailModal.isLoading = true;

  // self.$refs['sendEmail'].validate((valid) => {
    if (true) {
      let selectedContactList=[];
      tiyData.tParam.selected.forEach(function(item){
        if(item!=null &&  item !='null')
        selectedContactList.push(item);
      })
      let params = {
        contactUserList:selectedContactList,
        templateId:tiyData.tParam.templateId,
      };
      self.$apiEmail.sendAdEmails(params).then(response => {
        changeModelLoading(self, tiyData);
        if (response.success) {
          self.$Message.success({duration: 3, content: "成功发送邮件"+response.result});
          tiyData.tStatus.sendEmailModal.isShow = false;
          tiyData.tStatus.sendEmailModal.isLoading = false;

          self.search();
        } else {

          self.$Message.error(response.errorMessage);
        }
        tiyData.tParam.selected.splice(0);
      });
    }else {
      changeModelLoading(self, tiyData);
    }
  // });
};

//查询待开发客户
export const webList = (self,tiyData) => {
  self.$Spin.show();
  self.$ySpliceAll(tiyData.tData.contactUserList);

  let param = {
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "email": tiyData.tParam.email.trim(),
    "type": tiyData.tParam.type.trim(),
  };

  self.$apiEmail.queryContactUserList(param).then(function (response) {
    if(response.success){
      let emailPage = response.result;
      tiyData.tPage.total = emailPage.total;
      tiyData.tPage.stepNumber = emailPage.pageSize;
      emailPage.list.forEach(
        function (item) {
          tiyData.tData.contactUserList.push(item);
        }
      );
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
};


function changeModelLoading(self, tiyData) {

  tiyData.tStatus.sendEmailModal.isLoading = false;
  // tiyData.tStatus.modalDelete.isLoading = false;
  // self.$nextTick(function () {
  //   tiyData.tStatus.modalDelete.isLoading = true;
  // });
  //
  // tiyData.tStatus.modalAdd.isLoading = false;
  // self.$nextTick(function () {
  //   tiyData.tStatus.modalAdd.isLoading = true;
  // });
}
